<template>
  <div class="zdfb">
    <div class="head">
      <span>自动分班</span>
      <span style="font-size: 16px; margin-left: 50px">专业：</span>
      <el-input v-model="zymc" placeholder="请输入内容"></el-input>
      <button @click="query">查询</button>
      <button @click="fb">分班</button>
    </div>

    <el-table
      v-loading="loading1"
      ref="multipleTable"
      :data="wfb"
      tooltip-effect="dark"
      height="720"
      border
      class="table"
    >
      <el-table-column type="index" label="未分班" width="70">
      </el-table-column>
      <el-table-column prop="xm" label="姓名" width="110"> </el-table-column>
      <el-table-column prop="ksh" label="考生号" width="180"> </el-table-column>
      <el-table-column prop="xbdm" label="性别" width="80"> </el-table-column>
      <el-table-column prop="csny" label="出生年月" width="100">
      </el-table-column>
      <el-table-column prop="lqzy" label="专业名称" width="170">
      </el-table-column>
      <el-table-column prop="sfdm" label="省份"> </el-table-column>
    </el-table>

    <el-table
      v-loading="loading2"
      ref="multipleTable"
      :data="yfb"
      tooltip-effect="dark"
      height="720"
      border
      class="table2"
    >
      <el-table-column type="index" label="已分班" width="70">
      </el-table-column>
      <el-table-column prop="xm" label="姓名" width="110"> </el-table-column>
      <el-table-column prop="ksh" label="考生号" width="180"> </el-table-column>
      <el-table-column prop="xb" label="性别" width="80"> </el-table-column>
      <el-table-column prop="csny" label="出生年月" width="100">
      </el-table-column>
      <el-table-column prop="lqzy" label="专业名称" width="170">
      </el-table-column>
      <el-table-column prop="sfmc" label="省份"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { request } from "../../network/request";
export default {
  name: "",
  data() {
    return {
      zymc: "",
      loading1: false,
      loading2: false,
      wfb: [],
      yfb: [],
    };
  },
  methods: {
    query() {
      this.loading1 = true;
      this.loading2 = true;
      request({
        url: "http://118.31.51.131:8081/api/zsxt/fbgl/zswfb",
        method: "post",
        params: {
          zymc: this.zymc,
          token: sessionStorage.getItem("token"),
        },
      }).then((value) => {
        console.log(value);
        this.loading1 = false;
        this.wfb = value.data;
      });

      request({
        url: "http://118.31.51.131:8081/api/zsxt/fbgl/zsyjfb",
        method: "post",
        params: {
          zymc: this.zymc,
          token: sessionStorage.getItem("token"),
        },
      }).then((value) => {
        console.log(value);
        this.loading2 = false;
        this.yfb = value.data;
      });
    },
    fb() {
      request({
        url: "http://118.31.51.131:8081/api/zsxt/fbgl/zdfb",
        method: "post",
        params: {
          zymc: this.zymc,
          token: sessionStorage.getItem("token"),
        },
      }).then((value) => {
        console.log(value);
        if (value.data == 0) {
          alert("未配置分班信息，分班失败");
        } else {
          this.query();
        }
      });
    },
  },
  beforeCreate() {
    if (sessionStorage.getItem("token") == null) {
      this.$router.push("/login");
    } else {
      let token = sessionStorage.getItem("token");
      let length = sessionStorage.getItem("token").length;
      if (token[length - 3] == "0") {
        this.$router.replace("/login");
      }
    }
  },
  components: {},
};
</script>

<style scoped>
.head {
  height: 80px;
  border-bottom: 1px solid black;
}
.head span {
  font-size: 20px;
  line-height: 80px;
  margin-left: 25px;
}
.el-input {
  width: 200px;
}
.head button:nth-of-type(1) {
  margin-left: 820px;
}
.head button:nth-of-type(2) {
  margin-left: 100px;
}
button {
  width: 100px;
  height: 50px;
  border: none;
  outline: none;
  cursor: pointer;
  color: #fff;
  background-color: rgb(192, 51, 56);
}
button:active {
  opacity: 0.8;
}
.table {
  width: 50%;
  border-right: 1px solid #000;
}
.table2 {
  position: absolute;
  left: 50%;
  top: 81px;
  width: 50%;
}
.zdfb ::v-deep .el-table .cell {
  text-align: center;
}
</style>